/* 
  * registr.js
  * eLearning BG
  * Copyright 2012 - Vladislav Rumenov & Mariyan Stamenov
*/

$(document).ready(function(){

//get the height and width of the page
var window_width = $(window).width();
var window_height = $(window).height();

//vertical and horizontal centering of modal window(s)
/*we will use each function so if we have more then 1 
modal window we center them all*/
$('.modal_window').each(function(){
	
	//get the height and width of the modal
	var modal_height = $(this).outerHeight();
	var modal_width = $(this).outerWidth();
	
	//calculate top and left offset needed for centering
	var top = (window_height-modal_height)/2;
	var left = (window_width-modal_width)/2;
	
	//apply new top and left css values 
	$(this).css({'top' : top , 'left' : left});
	
});

	
	$('.activate_modal').click(function(){
			
		  //get the id of the modal window stored in the name of the activating element       
		  var modal_id = $(this).attr('name');
		  
		  //use the function to show it
		  show_modal(modal_id);
		  
	});
	
	$('.close_modal').click(function(){
		
		//use the function to close it
		close_modal();
		
	});
	
});

//THE FUNCTIONS

function close_modal(){
	
	//hide the mask
	$('#mask').fadeOut(500);
	
	//hide modal window(s)
	$('.modal_window').fadeOut(500);
	
}
function show_modal(modal_id){

	//set display to block and opacity to 0 so we can use fadeTo
	$('#mask').css({ 'display' : 'block', opacity : 0});
	
	//fade in the mask to opacity 0.8 
	$('#mask').fadeTo(500,0.8);
	 
	 //show the modal window
	$('#'+modal_id).fadeIn(500);
	
}
$(document).ready(function(){ // zapochvane na funkciqta
		$("#userResult").hide();  // skrivane na spana
		$("#username").blur(function(){ //izvejdane v span(); i zapochvane na funkcii
			$.post("includes/chekUser.php", {  //vzimane ot promenlivata chrez POST();
				username : $("#username").val() //proverqvane za usernameID
				
			}, function(response){ //otgovor
				$("#userResult").fadeOut("slow"), // zakrivane
				$("#userResult").html(response),// izvejdane
				$("#userResult").fadeIn("slow"); // skrivane
			}); 
		});
		});

		
		
		/* email */
		
		$(document).ready(function(){ // zapochvane na funkciqta
		$("#userResultE").hide();  // skrivane na spana
		$("#email").blur(function(){ //izvejdane v span(); i zapochvane na funkcii
			$.post("includes/chekEmail.php", {  //vzimane ot promenlivata chrez POST();
				email : $("#email").val() //proverqvane za usernameID
				
			}, function(response1){ //otgovor
				$("#userResultE").fadeOut("slow"), // zakrivane
				$("#userResultE").html(response1),// izvejdane
				$("#userResultE").fadeIn("slow"); // skrivane
			}); 
		});
		});
		
		/* real_name */
		
		$(document).ready(function(){ // zapochvane na funkciqta
		$("#userResultR").hide();  // skrivane na spana
		$("#real_name").blur(function(){ //izvejdane v span(); i zapochvane na funkcii
			$.post("includes/chekName.php", {  //vzimane ot promenlivata chrez POST();
				real_name : $("#real_name").val() //proverqvane za usernameID
				
			}, function(response2){ //otgovor
				$("#userResultR").fadeOut("slow"), // zakrivane
				$("#userResultR").html(response2),// izvejdane
				$("#userResultR").fadeIn("slow"); // skrivane
			}); 
		});
		});
		
				/* family */
		
		$(document).ready(function(){ // zapochvane na funkciqta
		$("#userResultF").hide();  // skrivane na spana
		$("#family").blur(function(){ //izvejdane v span(); i zapochvane na funkcii
			$.post("includes/chekFamily.php", {  //vzimane ot promenlivata chrez POST();
				family : $("#family").val() //proverqvane za usernameID
				
			}, function(response3){ //otgovor
				$("#userResultF").fadeOut("slow"), // zakrivane
				$("#userResultF").html(response3),// izvejdane
				$("#userResultF").fadeIn("slow"); // skrivane
			}); 
		});
		});
		
/*panel_icon*/
	$(document).ready(function(){
		$('.pic').hover(function(){
		 $(this).stop().animate({
		  "opacity" : .5
		 });
		}, function(){
		 $(this).stop().animate({
		  "opacity" : 1
		 });
		});
	});
	
